﻿using Data.Car_Rental;
using Entity.Car_Rental;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Entity;
namespace Background.Controllers
{
    public class LeaveMsgController : Controller
    {

        LeaveMsgRepository leaveMsgRepository = new LeaveMsgRepository();
        //
        // GET: /LeaveMsg/

        public ActionResult Index(int? page)
        {
            return View(new PagedList<LevelMsg>(leaveMsgRepository.GetModel<LevelMsg>().Where(i => i.Status == 100), page ?? 1, 10));
        }

        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(LevelMsg entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.UpdateDate = DateTime.Now;
            entity.Status = 100;
            entity.FromUser = 0;
            leaveMsgRepository.Insert(entity);
            return RedirectToAction("Index");
        }
        public ActionResult Details(int id)
        {
            return View(leaveMsgRepository.Find<LevelMsg>(id));
        }
        public ActionResult Delete(int id)
        {
            leaveMsgRepository.Delete(new LevelMsg { LevelMsgID = id });
            return RedirectToAction("Index");
        }

        public ActionResult Review(int levelMsgID)
        {
            return View();
        }

        public ActionResult Review(FormCollection form)
        {
            LevelMsgReplay entity = new LevelMsgReplay();
            entity.Content = form["Content"];
            entity.CreateDate = DateTime.Now;
            entity.LevelMsgID = Convert.ToInt64(form["LevelMsgID"]);
            leaveMsgRepository.CreateLeaveMsgReplay(entity);
            return RedirectToAction("Index");
        }

    }
}
